<template>
    <div class="table">
        <div class="container">
            <div class="handle-box" style="text-align: right">
                <!--<el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10"></el-input>-->
                <!--<el-button type="primary" icon="search" @click="search">搜索</el-button>-->
                <!--<el-button type="primary" @click="add" style="">添加管理员</el-button>-->
            </div>
            <el-table :data="tableData" border class="table" ref="multipleTable">
                <el-table-column prop="user_name" label="用户姓名" sortable></el-table-column>
                <el-table-column prop="mobile" label="电话" sortable></el-table-column>
                <el-table-column prop="centre" label="县区"></el-table-column>
                <el-table-column prop="working_group" label="班组"></el-table-column>
                <el-table-column prop="posts" label="岗位"></el-table-column>
                <el-table-column label="选择" width="120" align="center" fixed="left">
                    <template slot-scope="scope">
                        <!--<el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>-->
                        <!--<el-button type="text" icon="el-icon-delete" class="red" @click="handleDelete(scope.$index, scope.row)">删除</el-button>-->
                        <input type="checkbox" :value="scope.row.id" v-model="ids">
                    </template>
                </el-table-column>
            </el-table>
            <!--<div class="pagination">-->
            <!--<el-pagination background @current-change="handleCurrentChange" layout="prev, pager, next" :total="1000">-->
            <!--</el-pagination>-->
            <!--</div>-->
            <div class="block">
                <span class="demonstration"></span>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="currentPage1"
                    :page-size="pageSize"
                    layout="total, prev, pager, next"
                    :total="totalRow">
                </el-pagination>
            </div>

            <div style="margin-top: 1rem;text-align: center;">
                <el-button type="primary" size="medium" @click="submitForm('ruleForm2')">添加</el-button>
                <!--<el-button @click="getCheckedNodes">获取</el-button>-->
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        components:{
        },
        name: 'add-student',
        data() {
            return {
                select_word: '',
                tableData: [],
                editVisible: false,

                roleId: '', // 管理员id

                pageSize: 0,
                totalRow: 0,
                currentPage1: 0,

                ids: [],
            }
        },
        created() {
        },
        props: ['uid'],
        methods: {
            loadopen() {
                this.loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.2)'
                });
                setTimeout(() => {this.loading.close();}, 5000);
            },
            loadclose() {
                this.loading.close();
            },
            treeClick(){this.ids = [];this.getData();},
            // 获取列表数据
            getData(pageNumber) {
                this.config.post('/admin/role/findUser', {pageNum: pageNumber?pageNumber:1}).then(res=>{
                    if(res.data.code==='0'){
                        this.tableData = res.data.page.list;
                        this.pageSize = res.data.page.pageSize;
                        this.totalRow = res.data.page.totalRow;
                        this.currentPage1 = res.data.page.pageNumber;
                    }else {
                        this.$message.error(this.config.handleError(res.data));
                    }
                })
            },
            search() {
            },
            // 分页导航
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.getData(val);
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            // 删除
            handleDelete(index, row) {
                this.$confirm('确定删除此管理员?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.loadopen();
                    this.config.post('/admin/manager/delete', {userId: row.user_id}).then(res=>{
                        this.loadclose();
                        if(res.data.code==='0'){
                            this.$message.success(res.data.message);
                            this.getData();
                        }else {
                            this.$message.error(this.config.handleError(res.data));
                        }
                    });
                }).catch(() => {
                });
            },
            // 添加/编辑完成（子组件调用此方法）
            roleDone(str) {
                this.editVisible = false;
                this.getData();
            },
            // 保存编辑
            submitForm() {
                // console.log(this.ids)
                if(!this.ids.length) return;
                this.loadopen();
                this.config.post2('/admin/role/addUserToRole', {
                    roleId: this.uid,
                    ids: this.ids.join(','),
                }).then(res=>{
                    this.loadclose();
                    if(res.data.code==='0'){
                        this.$message.success(res.data.message);
                        this.getData();
                    }else {
                        this.$message.error(this.config.handleError(res.data));
                    }
                });
            },
        }
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
</style>
